package com.SyDeck.sdPerkSystem.prop;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Properties;

/**
 *
 * @author Deck & Sammy
 */
public class propertiesMethods extends Properties {

    private String filename;

    public propertiesMethods(String file) {
        this.filename = file;
    }

    public void loadPro() {
        File file = new File(this.filename);
        if (file.exists()) {
            try {
                load(new FileInputStream(this.filename));
            } catch (IOException e) {
            }
        }
    }

    public void SavePro(String str) {
        try {
            store(new FileOutputStream(this.filename), str);
        } catch (IOException e) {
        }
    }

    public int getInteger(String key, int value) {
        if (containsKey(key)) {
            return Integer.parseInt(getProperty(key));
        }
        put(key, String.valueOf(value));
        return value;
    }

    public float getfloat(String key, float value) {
        if (containsKey(key)) {
            return Float.parseFloat(getProperty(key));
        }
        put(key, String.valueOf(value));
        return value;
    }

    public String getString(String key, String value) {
        if (containsKey(key)) {
            return getProperty(key);
        }
        put(key, value);
        return value;
    }

    public ArrayList<String> getPermissions(String key, String value) {
        if (containsKey(key)) {
            ArrayList<String> permissions = new ArrayList<String>();
            permissions.addAll(Arrays.asList(getProperty(key).split(";")));
            put(key, value);
            return permissions;
        }
        put(key, value);
        return null;
    }
}
